package com.alibaba.controller;

import com.alibaba.annotation.SystemLog;
import com.alibaba.common.ResponseResult;
import com.alibaba.define.service.request.AddCommentRequest;
import com.alibaba.define.domain.vo.PageVO;
import com.alibaba.define.service.CommentService;
import com.alibaba.enums.CommentTypeEnum;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author : hanyang
 * @date : 2023-11-04 16:08
 **/

@RestController
@RequestMapping("/comment")
@Slf4j
public class CommentController {

    @Resource
    CommentService commentService;

    @GetMapping("/commentList")
    @SystemLog(businessName = "查询评论列表")
    public ResponseResult<PageVO> commentList(Long articleId, Integer pageNum, Integer pageSize) {
        log.info("CommentController#commentList() request[articleId:{}, pageNum:{}, pageSize:{}]", articleId, pageNum, pageSize);
        return commentService.commentList(CommentTypeEnum.ARTICLE.getCode(), articleId, pageNum, pageSize);
    }

    @PostMapping
    @SystemLog(businessName = "添加评论")
    public ResponseResult<Void> addComment(@RequestBody AddCommentRequest addCommentRequest) {
        log.info("CommentController#addComment() request:{}", JSON.toJSONString(addCommentRequest));
        return commentService.addComment(addCommentRequest);
    }

    @GetMapping("/linkCommentList")
    @SystemLog(businessName = "查询友链评论列表")
    public ResponseResult<PageVO> linkCommentList(Integer pageNum, Integer pageSize) {
        log.info("CommentController#linkCommentList() request[pageNum:{}, pageSize:{}]", pageNum, pageSize);
        return commentService.commentList(CommentTypeEnum.LINK.getCode(), null, pageNum, pageSize);
    }
}
